package com.godofgamblers.hotelmanagementsystem.mapper;


import com.godofgamblers.hotelmanagementsystem.pojo.Room;
import com.godofgamblers.hotelmanagementsystem.pojo.RoomCount;
import com.godofgamblers.hotelmanagementsystem.pojo.Room_Type;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wzx
 * @date 2019/10/14 - 9:45
 */

/**
 * 房间类型表相关数据库操作
 */
@Repository
public interface Room_typeMapper {
    /**
     * 查询：
     * 查询所有的room_type表中的对象：即所有的房间类型信息
     * 返回Room_Type pojo类集合
     *
     * @return返回值为List<Room_Type>集合
     */
    @Select("select * from room_type")
    public List<Room_Type> showAllItem();

    /**
     * 根据id查找房间类型名称
     * @param room_type_id
     * @return
     */
    @Select("select room_type_name from room_type where room_type_id=#{room_type_id}")
    public String selectRoomTypeNameById(Integer room_type_id);

    /**
     * 修改：
     * 修改room_type表中各项数据中的room_type_discount字段值
     *
     * @param room_type_discount 前端获取到的room_type_discount折扣值
     */
    @Update("update room_type set room_type_discount = #{room_type_discount}")
    public void changeAllItem_Discount(BigDecimal room_type_discount);

    /**
     * 修改：（用于恢复至全场折扣之前各个房间的折扣状态）
     * 通过room_type中的属性room_type_id确定room_type表中的数据行  修改room_type_discount字段的值
     *
     * @param room_type room_type POJO类
     */
    @Update("update room_type set room_type_discount = #{room_type_discount},room_type_price=#{room_type_price} where room_type_id = #{room_type_id}")
    public void changeOneItem_Discount(Room_Type room_type);

    @Update("update room_type set room_type_discount = #{room_type_discount} where room_type_id = #{room_type_id}")
    public void changeOneItem(Room_Type room_type);

    /**
     * 增加库存
     * 根据room中的属性room_type_id来确定哪个类型的房间库存增加
     * @param room
     */
    @Update("update room_type set room_type_stock = room_type_stock+1 where room_type_id = #{room_type_id}")
    public void addStockById(Room room);
    /**
     * 减少库存
     * 根据room中的属性room_type_id来确定哪个类型的房间库存减少
     * @param room
     */
    @Update("update room_type set room_type_stock = room_type_stock-1 where room_type_id = #{room_type_id}")
    public void reduceStockById(Room room);


    /**
     * 查找全场折扣
     * @param room_type_id 房间类型id
     * @return Room_type 封装房间类型、全场折扣
     */
    @Select("select room_type_discount,room_type_price,room_type_name from room_type where room_type_id=#{room_type_id} and flag=1")
    public Room_Type findAllDiscountAndPrice(Integer room_type_id);

    /**
     * 通过房间类型id查询最大库存
     * @param room_type_id 房间类型id
     * @return int 封装最大房间库存
     */
    @Select("select room_type_stock,room_type_name from room_type where room_type_id=#{room_type_id} and flag=1")
   public Room_Type offlineFindMaxStockByRoomTypeId(Integer room_type_id);

    /**
     *  查询所有房间类型
     * @return  List<Room_type>
     */
    @Select("select room_type_id,room_type_name from room_type where flag = 1")
   public List<Room_Type> findRoomTypeInfos();

    /**
     * 根据房间id查询房间类型信息
     * @param room_type_id
     * @return
     */
    @Select("select room_type_name from room_type where room_type_id=#{room_type_id} and flag=1")
    public Room_Type findRoomTypeInfoByRoomTypeid(Integer room_type_id);
//根据房间类型id,找到其类型所有信息
    @Select("select * from room_type where room_type_id = #{room_type_id} and flag = 1")
    public Room_Type findRoomType(Integer room_type_id);

    @Select("select room_type_stock from room_type where room_type_id = #{room_type_id} and flag = 1")
    public Integer findNowStock(Integer room_type_id);

    @Select("SELECT room_type_stock AS room_count,room_type_name,room_type_id\n" +
            "FROM room_type")
    public List<RoomCount> getRoomsCountByDay();


    //根据房间类型id，找到房间名
    @Select("select room_type_name from room_type where room_type_id = #{room_type_id}")
    public String findRoomTypeName(Integer room_type_id);
}
